<template>
  <div class="home-new">
      <!-- 标题 副标题 -->
    <MianBan title="新鲜好物" fubiaoti="新鲜出炉 品质靠谱">
      <template #right><XTXGenDuo path="/" /></template>
    <div ref="target" style="position: relative;height: 426px;">
      <!-- Transition vue组件的动画 -->
     <Transition name="fade">
      <!-- 面板内容 -->
      <ul class="goods-list" v-if="goods.length">
        <li v-for="item in goods" :key="item.id">
          <RouterLink :to="`/product/${item.id}`">
            <img :src="item.picture" alt="">
            <p class="name ellipsis">{{item.name}}</p>
            <p class="price">&yen;{{item.price}}</p>
          </RouterLink>
        </li>
      </ul>
      <MianbanGujia bg="#f0f9f4" v-else/>
    </Transition>
    </div>
    </MianBan>
  </div>
</template>
<script>
import MianBan from './MianBan-Panel .vue'
import MianbanGujia from './MianbanGujia.vue'
import { ref } from 'vue'
import { chaKanQuanBuqinqiu } from '@/Api/index'
import { lanjiazhai } from '@/components/hooks-lanjiazhai'
export default {
  name: 'HomeNew',
  components: { MianBan, MianbanGujia },
  setup () {
    // const goods = ref([])
    // chaKanQuanBuqinqiu().then(data => {
    //   goods.value = data.result
    // })
    // 数据懒加载 写法
    const target = ref(null)
    const result = lanjiazhai(target, chaKanQuanBuqinqiu)
    return { goods: result, target }
  }
}
</script>
<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();// 调用动画
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
